#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

inline static int read(){
    int sum=0,neg=0,ch=getchar();
    while(!isdigit(ch)) neg|=(ch=='-'),ch=getchar();
    while(isdigit(ch)) sum=sum*10+(ch^48),ch=getchar();
    return neg?-sum:sum;
}
constexpr int inf=0x3f3f3f3f;
int n,m,_m,C,ps[1000005],L[500005],arr[1000005],lst[1000005];
vector<pair<int,ll>>v0;
vector<int>v1,vec[1000005],ans; ll b[500005],Ans=LLONG_MAX;
signed main(){
    freopen("list.in","r",stdin);
    freopen("list.out","w",stdout);
    n=read();
    for(int i=1,p=0,t;i<=n;L[++i]=p,m+=t) for(int j=t=read();j;j--) arr[p++]=read();
    memcpy(ps+1,arr,4*m),sort(ps+1,ps+m+1),_m=m,m=unique(ps+1,ps+m+1)-ps-1,C=read();
    for(int i=1;i<=n;i++) b[i]=(ll)read()*i; memset(lst+1,0xc0,4*n),v0={{1,0}};
    for(int i=1;i<=n;i++) for(int j=L[i];j<L[i+1];j++)
        vec[lower_bound(ps+1,ps+m+1,arr[j])-ps].push_back(i);
    for(int i=1,k,p;i<=m;i++){
        k=0,p=ps[i]; for(int j:vec[i]) arr[k++]=p-lst[j];
        sort(arr,arr+k,greater<int>()),v0[0].second+=b[k];
        for(int j=0;j<k;j++) if(arr[j]<inf) v0.emplace_back(arr[j]+1,b[j]-b[j+1]);
        for(int j:vec[i]) lst[j]=p;
    } memset(lst+1,0x7f,4*n); ll sum=(ll)_m*C,val=0;
    for(int i=m,p=ps[m];i>=1;p=ps[--i])
        for(int j:vec[i]) v1.emplace_back(lst[j]-p),lst[j]=p;
    sort(v0.begin(),v0.end()),sort(v1.begin(),v1.end());
    for(int i=0,j=0,p=0,t;i<v0.size();p=t){
        for(t=v0[i].first;i<v0.size() && v0[i].first==t;i++) val+=v0[i].second;
        for(;j<v1.size() && v1[j]<=t;j++) val+=(v1[j]-p)*sum,p=v1[j],sum-=C;
        if((val+=(t-p)*sum)<Ans) ans={t},Ans=val; else if(val==Ans) ans.push_back(t);
    } printf("%lld %zu\n",Ans,ans.size());
    for(int i:ans) printf("%d ",i); return puts(""),0;
}
